package com.hebeiwangxiaozhang.user.service.controller;

import com.hebeiwangxiaozhang.response.CommonResponse;
import com.hebeiwangxiaozhang.response.ResponseCode;
import com.hebeiwangxiaozhang.response.ResponseUtils;
import com.hebeiwangxiaozhang.user.service.pojo.Ouath2ClientRegister;
import com.hebeiwangxiaozhang.user.service.pojo.User;
import com.hebeiwangxiaozhang.user.service.service.UserRegisterService;
import org.apache.tomcat.util.http.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
public class UserRegisterLoginController {

    @Autowired
    private UserRegisterService userRegisterService;

    //用户名 + 密码注册
    @RequestMapping("/register/name-password")
    public CommonResponse namePasswordRegister(@RequestBody User user) {
        return userRegisterService.namePasswordRegister(user);
    }

    //电话验证码
    @RequestMapping("/register/phone-code")
    public CommonResponse phoneCodeRegister(@RequestParam String phoneNumber, @RequestParam String code) {
        return userRegisterService.phoneCodeRegister(phoneNumber, code);
    }

    //第三方账号登录
    @GetMapping("/register/gitee")
    public CommonResponse thirdPartSystem(HttpServletRequest request) {
        return userRegisterService.thirdPartSystem(request, "GITEE");
    }

    //用户名密码登录
    @RequestMapping("/login")
    public CommonResponse login(@RequestParam String username, String password) {
        return userRegisterService.login(username, password);
    }

    @RequestMapping("/third-part-app/request")
    public CommonResponse thirdParAppRequest(
            @RequestHeader String personId,
            @RequestBody Ouath2ClientRegister ouath2ClientRegister) {
        return userRegisterService.thirdParAppRequest(personId, ouath2ClientRegister);
    }

    @RequestMapping("/third-part-app/request/status")
    public CommonResponse checkThirdParAppRequestStatus(@RequestHeader String personId) {
        return userRegisterService.checkThirdParAppRequestStatus(personId);
    }

    @RequestMapping("/third-part-app/request/approve")
    public CommonResponse checkThirdParAppRequestApprove(@RequestParam String appName) {
        return userRegisterService.checkThirdParAppRequestApprove(appName);
    }
}
